//
//  NSObject+Common.m
//  CodeCollection
//
//  Created by sfpay on 14/12/24.
//  Copyright (c) 2014年 zainxiong. All rights reserved.
//

/*
#import "NSObject+Common.h"
#import <JDStatusBarNotification/JDStatusBarNotification.h>
#import <MBProgressHUD/MBProgressHUD.h>

//TODO: 缓存文件名设置
#define kImageCacheDirName          @"ImageCache"
#define kResponseDataCacheDirName   @"ResponseDataCache"

@implementation NSObject (Common)

- (NSString *)tipFromError:(NSError *)error{
    if (error && error.userInfo) {
        NSMutableString *tipStr = [[NSMutableString alloc] init];
        if ([error.userInfo objectForKey:@"msg"]) {
            NSArray *msgArray = [[error.userInfo objectForKey:@"msg"] allValues];
            NSUInteger num = [msgArray count];
            for (int i = 0; i < num; i++) {
                NSString *msgStr = [msgArray objectAtIndex:i];
                if (i+1 < num) {
                    [tipStr appendString:[NSString stringWithFormat:@"%@\n", msgStr]];
                }else{
                    [tipStr appendString:msgStr];
                }
            }
        }else{
            if ([error.userInfo objectForKey:@"NSLocalizedDescription"]) {
                tipStr = [error.userInfo objectForKey:@"NSLocalizedDescription"];
            }else{
                [tipStr appendFormat:@"ErrorCode%ld", (long)error.code];
            }
        }
        return tipStr;
    }
    return nil;
}

//TODO: 显示遮盖 with 显示信息 , 一秒后消失
- (void)showHudTipStr:(NSString *)tipStr {
    if ([tipStr length] > 0 && tipStr) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];//指定在哪个view显示遮盖
        hud.mode = MBProgressHUDModeText;
        hud.labelText = tipStr;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1.0];  //一秒后消失
    }
}

//TODO: 在status bar上显示信息
- (void)showStatusBarQueryStr:(NSString *)tipStr; {
    [JDStatusBarNotification showWithStatus:tipStr styleName:JDStatusBarStyleSuccess];
    [JDStatusBarNotification showActivityIndicator:YES indicatorStyle:UIActivityIndicatorViewStyleWhite];
}

- (void)showStatusBarSuccessStr:(NSString *)tipStr{
    if ([JDStatusBarNotification isVisible]) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
            [JDStatusBarNotification showWithStatus:tipStr dismissAfter:1.5 styleName:JDStatusBarStyleSuccess];
        });
    }else{
        [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
        [JDStatusBarNotification showWithStatus:tipStr dismissAfter:1.0 styleName:JDStatusBarStyleSuccess];
    }
}
- (void)showStatusBarError:(NSError *)error{
    if ([JDStatusBarNotification isVisible]) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
            [JDStatusBarNotification showWithStatus:[self tipFromError:error] dismissAfter:1.5 styleName:JDStatusBarStyleError];
        });
    }else{
        [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
        [JDStatusBarNotification showWithStatus:[self tipFromError:error] dismissAfter:1.5 styleName:JDStatusBarStyleError];
    }
}
- (void)showStatusBarProgress:(CGFloat)progress{
    [JDStatusBarNotification showProgress:progress];
    
}
- (void)hideStatusBarProgress{
    [JDStatusBarNotification showProgress:0.0];
}

-(NSString* )pathInCacheDirectory:(NSString *)fileName; {
    static NSString *cahePathFullName = @"";
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSString *cacheDir = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)[0];
        cahePathFullName = [cacheDir stringByAppendingPathComponent:fileName];
    });
    return cahePathFullName;
}

-(BOOL) createDirInCache:(NSString *)dirName {
    NSString *cacheDir = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)[0];
    NSString *cacheFullPath = [cacheDir stringByAppendingPathComponent:cacheDir];
    BOOL isDir = NO;
    BOOL existed = [[NSFileManager defaultManager] fileExistsAtPath:cacheFullPath isDirectory:&isDir];
    BOOL isCreate = NO;
    NSError *err = nil;
    if (!existed && isDir) {
        isCreate = [[NSFileManager defaultManager] createDirectoryAtPath:cacheFullPath withIntermediateDirectories:YES attributes:nil error:&err];
    }
    
    if (err) {
        NSLog(@"create cache dir fail\n");
    }
    
    if (existed) {
        isCreate = NO;
    }
    
    return isCreate;
}


@end

*/






